package com.combining.e_composite.impl;

import java.util.Iterator;
import java.util.ArrayList;

import com.combining.e_composite.face.Quackable;

/**
 * 组合模式，组合要和叶节点元素一样实现相同的接口
 * 
 * @author dell
 * 
 */
public class Flock implements Quackable {
	ArrayList<Quackable> quackers = new ArrayList<Quackable>();

	public void add(Quackable quacker) {
		quackers.add(quacker);
	}

	public void quack() {
		Iterator<Quackable> iterator = quackers.iterator();
		while (iterator.hasNext()) {
			Quackable quacker = (Quackable) iterator.next();
			quacker.quack();
		}
	}

}
